use super::macro_economics::MacroEconomicIndicators;
use serde::{Serialize, Deserialize};

/// 政策工具类型
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum PolicyTool {
    Monetary {
        interest_rate_change: f64,  // 利率调整幅度
        money_supply_growth: f64,   // 货币供应增长率
    },
    Fiscal {
        tax_rate: f64,              // 税率调整
        government_spending: f64,   // 政府支出变化
    },
    Trade {
        tariff_rate: f64,           // 关税税率
        export_subsidy: f64,        // 出口补贴
    },
    Regulatory {
        business_regulation: f64,   // 商业监管强度
        labor_regulation: f64,      // 劳动法规强度
    },
}

/// 政策影响评估
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct PolicyImpact {
    pub gdp_effect: f64,
    pub growth_effect: f64,
    pub inflation_effect: f64,
    pub employment_effect: f64,
    pub interest_rate_effect: f64,
    pub consumer_confidence_effect: f64,
    pub trade_balance_effect: f64,
    pub fiscal_effect: f64,
}

impl PolicyImpact {
    /// 合并多个政策影响
    pub fn combine(mut self, other: &PolicyImpact) -> Self {
        self.gdp_effect += other.gdp_effect;
        self.growth_effect += other.growth_effect;
        self.inflation_effect += other.inflation_effect;
        self.employment_effect += other.employment_effect;
        self.interest_rate_effect += other.interest_rate_effect;
        self.consumer_confidence_effect += other.consumer_confidence_effect;
        self.trade_balance_effect += other.trade_balance_effect;
        self.fiscal_effect += other.fiscal_effect;
        self
    }
}

impl PolicyTool {
    /// 评估政策影响
    pub fn estimate_impact(&self, indicators: &MacroEconomicIndicators) -> PolicyImpact {
        match self {
            PolicyTool::Monetary { interest_rate_change, money_supply_growth } => {
                let inflation_effect = money_supply_growth * 0.3 - interest_rate_change * 0.2;
                PolicyImpact {
                    gdp_effect: money_supply_growth * 0.5 - interest_rate_change * 0.3,
                    growth_effect: money_supply_growth * 0.2,
                    inflation_effect,
                    employment_effect: money_supply_growth * 0.1 - interest_rate_change * 0.05,
                    interest_rate_effect: *interest_rate_change,
                    consumer_confidence_effect: -interest_rate_change * 2.0,
                    trade_balance_effect: -interest_rate_change * 0.5,
                    fiscal_effect: 0.0,
                }
            }
            PolicyTool::Fiscal { tax_rate, government_spending } => {
                let multiplier = if indicators.unemployment > 0.07 { 1.5 } else { 1.0 };
                PolicyImpact {
                    gdp_effect: government_spending * 0.7 * multiplier - tax_rate * 0.5,
                    growth_effect: government_spending * 0.1 - tax_rate * 0.05,
                    inflation_effect: government_spending * 0.1 + tax_rate * 0.02,
                    employment_effect: government_spending * 0.05 - tax_rate * 0.02,
                    interest_rate_effect: government_spending * 0.01,
                    consumer_confidence_effect: -tax_rate * 5.0 + government_spending * 0.5,
                    trade_balance_effect: -government_spending * 0.1,
                    fiscal_effect: government_spending - tax_rate * indicators.gdp * 0.01,
                }
            }
            PolicyTool::Trade { tariff_rate, export_subsidy } => {
                PolicyImpact {
                    gdp_effect: -tariff_rate * 0.2 + export_subsidy * 0.3,
                    growth_effect: export_subsidy * 0.05,
                    inflation_effect: tariff_rate * 0.1,
                    employment_effect: export_subsidy * 0.03,
                    interest_rate_effect: 0.0,
                    consumer_confidence_effect: -tariff_rate * 3.0,
                    trade_balance_effect: tariff_rate * 0.5 + export_subsidy * 0.8,
                    fiscal_effect: tariff_rate * 0.3 - export_subsidy * 0.5,
                }
            }
            PolicyTool::Regulatory { business_regulation, labor_regulation } => {
                PolicyImpact {
                    gdp_effect: -business_regulation * 0.3 - labor_regulation * 0.2,
                    growth_effect: -business_regulation * 0.05,
                    inflation_effect: business_regulation * 0.05 + labor_regulation * 0.03,
                    employment_effect: labor_regulation * 0.02,
                    interest_rate_effect: 0.0,
                    consumer_confidence_effect: -business_regulation * 2.0,
                    trade_balance_effect: -business_regulation * 0.2,
                    fiscal_effect: 0.0,
                }
            }
        }
    }
}